﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace amigos_dropbox_gui
{
    public class Idioma
    {
        public Idioma()
        {

        }
        private static void AlteraThreadIdioma(string culture)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture, true);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture, true);
        }
        private static void AlteraCultura(Form frm, System.ComponentModel.ComponentResourceManager resx)
        {
            //Altera o nome do form
            frm.Text = resx.GetObject("$this.Text", System.Threading.Thread.CurrentThread.CurrentCulture).ToString();
            //Varre os controles do form aplicando a nova cultura
            foreach (Control ctrl in frm.Controls)
                resx.ApplyResources(ctrl, ctrl.Name, System.Threading.Thread.CurrentThread.CurrentCulture);
        }
        public void AjustaCultura(Form frm, string culture)
        {
            AlteraThreadIdioma(culture);
            System.ComponentModel.ComponentResourceManager resx = new System.ComponentModel.ComponentResourceManager(frm.GetType());
            AlteraCultura(frm, resx);
        }

        public string IdiomaDefault()
        {
            string idioma;
            XmlDocument doc = new XmlDocument();
            doc.Load(@"C:\Arquivos de programas\Overalt\Config.xml");
            XmlNode elemento;
            elemento = doc.SelectSingleNode("/overalt/language");
            idioma = elemento.InnerText;

            return idioma;
        }

        public void AlteraIdioma(string idioma)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(@"C:\Arquivos de programas\Overalt\Config.xml");
            XmlNode no = doc.SelectSingleNode("/overalt/language");
            
            no.InnerText = idioma;
            doc.Save(@"C:\Arquivos de programas\Overalt\Config.xml");
        }
    }
}
